<?php
// Force the browser to use no cache
//header ("Cache-Control: no-cache, must-revalidate");              // HTTP/1.1
//header ("Pragma: no-cache");                                      // HTTP/1.0

$date = date("r");

function enableAndDisableButtons(){
	if ($_GET['favorite'] == 'false' || $_GET['favorite'] == 'remove'){
		echo "<script type='text/javascript'>
				document.commands.add.disabled=false;
				document.commands.update.disabled=true;
				document.commands.remove.disabled=true;
				</script>";
	} else if ($_GET['favorite'] == 'true'){
		echo "<script type='text/javascript'>
			document.commands.add.disabled=true;
			document.commands.update.disabled=false;
			document.commands.remove.disabled=false;
			</script>";
	}
}

echo("
	<html>
	<head>
	<meta http-equiv=\"Cache-Control\" content=\"no-cache\"/>
	<meta http-equiv=\"Pragma\" content=\"no-cache\"/>
	<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
	<link rel=\"stylesheet\" type=\"text/css\" href=\"timeline.css\"/>
	<title> Google Timeline Mashup Project </title>
	</head>
	<script src='http://simile.mit.edu/timeline/api/timeline-api.js' type='text/javascript'></script>

<script>
	var tl;

function onLoad() {
	var eventSource = new Timeline.DefaultEventSource();
	var theme = Timeline.ClassicTheme.create();
	theme.event.label.width = 300;
	theme.event.bubble.width = 250;
	theme.event.bubble.height = 150;


	var bandInfos = [
	Timeline.createBandInfo({
		eventSource:    eventSource,
			date:           '".$date."',
			width:          '80%',
			intervalUnit:   Timeline.DateTime.DAY, 
			intervalPixels: 200,
			trackHeight: 2,
			trackGap: 0.5,
			theme: theme
			}),
		Timeline.createBandInfo({
			showEventText:  false,
				trackHeight:    0.5,
				trackGap:       0.2,
				eventSource:    eventSource,
				date:           '".$date."',
				width:          '20%', 
				intervalUnit:   Timeline.DateTime.MONTH, 
				intervalPixels: 300
				})
				];
			bandInfos[1].syncWith = 0;
			bandInfos[1].highlight = true;

			tl = Timeline.create(document.getElementById('my-timeline'), bandInfos);
			Timeline.loadXML('" . $xml_events_file . "', function(xml, url) { eventSource.loadXML(xml, url); });
		}

		var resizeTimerID = null;
		function onResize() {
			if (resizeTimerID == null) {
				resizeTimerID = window.setTimeout(function() {
					resizeTimerID = null;
					tl.layout();
					}, 500);
				}
			}
			</script>
				<body onload='onLoad();' onresize='onResize();'>
				<div id='frame'>
				<div id=\"header\"></div>
				<div style='background-color:#ddd; width:750px'>
					<h1 style='font-size:25px; color:#69c'>" . $calTitle . "'s Timeline</h1>
				</div>
				
				<div id='my-timeline' style='background-color:#fff; height: 300px; width: 750px; border: 1px solid #aaa'></div>
				
				<div align='center' style='padding: 15px; background-color:#ddd; width:720px'>
				<form name='commands' method='post'>
					<input type='button' value='Back' onClick=\"window.location.href='index.php';\"/>
					<input name='add' type='button' value='Add to favorites' onClick=\"window.location.href='timeline.php?title=" . $calTitle . "&url=" . $url . "&favorite=true';\"/>
					<input name='remove' type='button' value='Remove from favorites' onClick=\"window.location.href='timeline.php?title=" . $calTitle . "&url=" . $url . "&favorite=remove';\"/>
					<input name='update' type='button' value='Update feed' onClick=\"window.location.href='timeline.php?title=" . $calTitle . "&url=" . $url . "&favorite=true&update=true';\"/>
					<input type='hidden' value='Go to Google Calendar' onClick=\"window.location.href='http://www.google.com/calendar/embed?src=" . $url . "';\"/>
				</form>
				</div>
				
				<div style='background-color:#ddd; width:750px'>
					<h1 style='font-size:25px; color:#69c'>" . $calTitle . "'s Calendar</h1>
				</div>
				
				<div style='padding-bottom:15px'>
					<iframe src=\"http://www.google.com/calendar/embed?src=". $url ."\" style=\"background-color:#000; border: 0\" width=\"750\" height=\"600\" frameborder=\"0\" scrolling=\"no\"></iframe>
				</div>
				
				<div id=\"footer\"></div>
				</div>
				</body>
				</html>
				");
				
enableAndDisableButtons();
?>